<html>
<head><meta charset="utf-8"><title>futures unordered boxing (SOLVED) · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/futures.20unordered.20boxing.20(SOLVED).html">futures unordered boxing (SOLVED)</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="210344540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/futures%20unordered%20boxing%20%28SOLVED%29/near/210344540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> max <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/futures.20unordered.20boxing.20(SOLVED).html#210344540">(Sep 17 2020 at 03:26)</a>:</h4>
<p>hello, i'm new to rust. Have trouble figuring out how to deal with futures properly. The following example doesn't compile. I've tried Boxing (and Pin&lt;Box&lt;&gt;&gt;, and lots of stuff), but fail miserably for two days already. Reading up all info on futures didn't enlighten me at all. The actual problem requires .map()'ing the future and it becomes even more complicated, but i can't even figure out this simple example. Please help :)</p>
<div class="codehilite"><pre><span></span><code>// [dependencies]
// futures = &quot;*&quot;
// tokio = { version = &quot;*&quot;, features = [&quot;full&quot;] }
// reqwest = { version = &quot;*&quot;, features = [&quot;stream&quot;, &quot;gzip&quot;] }

use futures::stream::FuturesUnordered;
use futures::{Future, StreamExt};
use reqwest::{Result, Response, Client};

fn foo(client: &amp;Client) -&gt; impl Future&lt;Output=Result&lt;Response&gt;&gt; {
    client.get(&quot;https://google.com&quot;).send()
}

fn bar(client: &amp;Client) -&gt; impl Future&lt;Output=Result&lt;Response&gt;&gt; {
    client.get(&quot;https://yahoo.com&quot;).send()
}

#[tokio::main]
async fn main() {
    let mut unordered = FuturesUnordered::new();

    let client = reqwest::Client::new();

    unordered.push(foo(&amp;client));
    unordered.push(bar(&amp;client));

    loop {
        tokio::select! {
            Some(n) = unordered.next(), if ! unordered.is_empty() =&gt; {
                println!(&quot;got {:?}&quot;, n);
            },
            else =&gt; {
                break;
            },
        }
    }
}
</code></pre></div>



<a name="210350611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/futures%20unordered%20boxing%20%28SOLVED%29/near/210350611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> max <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/futures.20unordered.20boxing.20(SOLVED).html#210350611">(Sep 17 2020 at 05:53)</a>:</h4>
<p>SOLVED. apparently manually doing <code>Pin&lt;Box&lt;&gt;&gt;</code> is not the same as <code>.boxed()</code>, because the latter worked as intended.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>